﻿Public Class EnumerableInterfaceList(Of X, y)
  Inherits List(Of X)
  Implements IEnumerable(Of Y)

  Public Class EnumerableListEnumerator
    Implements IEnumerator(Of y)
    Private _entries As List(Of X) = Nothing
    Private _count As Integer = -1

    Public Sub New(ByVal el As List(Of X))
      Me._entries = el
    End Sub

    Public ReadOnly Property Current() As y Implements System.Collections.Generic.IEnumerator(Of y).Current
      Get
        If Me._entries IsNot Nothing AndAlso Me._count >= 0 AndAlso Me._count < Me._entries.Count Then
          Return CObj(Me._entries(Me._count))
        End If
        Return Nothing
      End Get
    End Property

    Public ReadOnly Property Current1() As Object Implements System.Collections.IEnumerator.Current
      Get
        Return Me.Current
      End Get
    End Property

    Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext
      If Me._entries IsNot Nothing AndAlso Me._count < Me._entries.Count - 1 Then
        Me._count += 1
        Return True
      End If
      Return False
    End Function

    Public Sub Reset() Implements System.Collections.IEnumerator.Reset
      Me._count = -1
    End Sub

    Private disposedValue As Boolean = False    ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
      If Not Me.disposedValue Then
        If disposing Then
          ' TODO: free other state (managed objects).
        End If

        ' TODO: free your own state (unmanaged objects).
        ' TODO: set large fields to null.
      End If
      Me.disposedValue = True
    End Sub

    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
      ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
      Dispose(True)
      GC.SuppressFinalize(Me)
    End Sub
  End Class

  Public Sub New()
    MyBase.New()
  End Sub

  Public Sub New(ByVal capacity As Integer)
    MyBase.New(capacity)
  End Sub

  Public Sub New(ByVal collection As Collections.Generic.IEnumerable(Of X))
    MyBase.New(collection)
  End Sub

  Shadows Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of y) Implements System.Collections.Generic.IEnumerable(Of y).GetEnumerator
    Return New EnumerableListEnumerator(Me)
  End Function

  Shadows Function GetEnumerator1() As System.Collections.IEnumerator
    Return New EnumerableListEnumerator(Me)
  End Function
End Class
